layui.use(['form', 'jquery'], function(){
    var form = layui.form;
    let $=layui.jquery;
    form.verify({
        title: function(value){
          if(value.length<=0){
            return '标题至少得有啊';
          }
        }
        ,orderby: [
          /^[\d]+$/
          ,'大哥!这是排序的输个数字好吗'
        ]
        ,content: function(value){
          layedit.sync(editIndex);
        }
      });

      let tmp_status=0;
      form.on('switch(m_status)', function(data){
       this.value=this.checked?1:0;
       tmp_status=this.value;
      });
      
      //监听提交
      form.on('submit(demo1)', function(data){
     
       data.field.m_status=tmp_status;
       console.log(data.field);
       $.ajax({
           url:"./addmenu",
           data:data.field,
           type:"post",
           dataType:"json"
       }).then(function(res)
       {
          layer.msg(res.msg,function()
          {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
          })
       })
        return false;
      });
})